/* cmd_i2ctools.h
   This example code is in the Public Domain (or CC0 licensed, at your option.)
   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

#pragma once
#include "driver/i2c.h"
#ifdef __cplusplus
extern "C" {
#endif

//相关常量宏定义
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C主机不需要写入缓冲区 */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C主机不需要读取缓冲区 */
#define WRITE_BIT I2C_MASTER_WRITE  /*!< I2C 主机写入模式 */
#define READ_BIT I2C_MASTER_READ    /*!< I2C 主机读取模式 */
#define ACK_CHECK_EN 0x1            /*!< I2C 主机将检测来自从设备的ack*/
#define ACK_CHECK_DIS 0x0           /*!< I2C 主机将检测来自从设备的ack */
#define ACK_VAL 0x0                 /*!< I2C ack 值 */
#define NACK_VAL 0x1                /*!< I2C nack 值 */

//全局静态变量，用于几个命令相关联处理
static gpio_num_t i2c_gpio_sda = 18;
static gpio_num_t i2c_gpio_scl = 19;
static uint32_t i2c_frequency = 100000;
static i2c_port_t i2c_port = I2C_NUM_0;

//注册i2ctools命令组
void register_i2ctools(void);

//注册i2c配置命令
static void register_i2cconfig(void);
//定义i2c配置命令参数
static struct {
    struct arg_int *port;
    struct arg_int *freq;
    struct arg_int *sda;
    struct arg_int *scl;
    struct arg_end *end;
} i2cconfig_args;

//注册读取从设备寄存器数据命令
static void register_i2cget(void);
//定义i2c读取命令参数
static struct {
    struct arg_int *chip_address;           //芯片地址
    struct arg_int *register_address;       //寄存器地址
    struct arg_int *data_length;            //数据长度
    struct arg_end *end;        
} i2cget_args;


//注册i2c写入从设备寄存器数据命令
static int do_i2cset_cmd(int argc, char **argv);
//定义i2c写入命令参数
static struct {
    struct arg_int *chip_address;           //芯片地址
    struct arg_int *register_address;       //寄存器地址
    struct arg_int *data;                   //数据
    struct arg_end *end;
} i2cset_args;
static void register_i2cdump(void);
//
static struct {
    struct arg_int *chip_address;
    struct arg_int *size;
    struct arg_end *end;
} i2cdump_args;

#ifdef __cplusplus
}
#endif